#include <stdio.h>
#include <stdlib.h>

void Print1(char** str, int start, int layer, int num, char** str1);
int count = -1;
int main()
{
    int n, i, j, k, sz;
    scanf("%d", &n);
    //序偶总个数
    sz = n * n;
    //将换行符读出缓存区
    getchar();
    //分配临时空间存储集合
    char* tem = (char*)calloc(2*n + 2, sizeof(char));
    scanf("%s", tem);
    //分配空间存储元素
    char* str = (char*)calloc(n, sizeof(char));
    //从临时空间读入元素
    for (i = 0; i < n; i++)
        str[i] = tem[2*i + 1];
    //销毁临时空间
    free(tem), tem = NULL;
    //分配空间存储所有序偶
    char** str1 = (char**)calloc(sz, sizeof(char*));
    for (i = 0; i < sz; i++)
        str1[i] = (char*)calloc(2*n + 2, sizeof(char));
    //向空间中写入序偶
    for (i = 0, k = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
            sprintf(str1[k], "<%c,%c>", str[i], str[j]);
            k++;
    }

    char** str2 = NULL;
    printf("{}\n");
    for (i = 1; i <= sz; i++)
    {
        // count = 0;
        if (i > 1)
        {
            char** temp = (char**)calloc(i - 1, sizeof(char*));
            if (temp == NULL)
            {
                perror("calloc");
                return 0;
            }
            str2 = temp;
        }
        for (j = 0; j < i - 1; j++)
            str2[j] = (char*)calloc(2*n + 2, sizeof(char));
        Print1(str1, 0, i, sz, str2);
    }

    return 0;
}

void Print1(char** str, int start, int layer, int num, char** str1)
{
    int i, j, k;
    if (1 == layer)
    {
        for (i = start; i < num; i++)
        {
            printf("{");
            for (j = 0; j <= count; j++)
                printf("%s,", str1[j]);
            printf("%s}\n", str[i]);
        }
    }
    else
    {
        count++;
        for (i = start; i <= num - layer; i++)
        {
            str1[count] = str[i];
            Print1(str, i + 1, layer - 1, num, str1);
        }
        count--;
    }

    return ;
}